﻿namespace Company.Core.Logger
{
    public class Logs
    {
        public static string path = AppDomain.CurrentDomain.BaseDirectory + "logs";
        public static object logLocker = new object();
        protected static void WriteLog(string type, string content)
        {
            lock (logLocker)
            {
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
                string filename = path + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".log";
                StreamWriter sw = File.AppendText(filename);
                string write_content = time + " " + type + ":" + content;
                sw.WriteLine(write_content);
                sw.Close();
            }
        }

        public static void Debug(string content) => WriteLog("DEBUG", content);
        public static void Info(string content) => WriteLog("INFO", content);
        public static void Error(string content) => WriteLog("ERROR", content);
        public static void Error(Exception ex) => WriteLog("ERROR", ex.Message + ex.StackTrace);
    }
}
